<template>
  <div v-drag>
    <div class="mask" @click="closePopup(false)"></div>
    <div class="edit_box" v-loading="loading">
      <div class="box_head">
        <p>编辑商品</p>
        <i @click="closePopup(false)"></i>
      </div>
      <div class="box_body">

        <div class="line">
          <span class="lab"><i class="mark_icon">*</i>可用量：</span>
          <div :class="{'error_border':tip_num===1}" >
            <el-input v-model.number="data.numbers" :class="{'error_border':tip_num===1}" min="0" placeholder="请输入可用量"
                      type="number" @input="setTip('','')"></el-input>
          </div>
        </div>

        <div class="line">
          <span class="lab"><i class="mark_icon">*</i>商品数量：</span>
          <div>
            <el-input v-model.number="data.productNumber" :class="{'error_border':tip_num===2}" min="0" placeholder="请输入商品数量"
                      type="number" @input="setTip('','')"></el-input>
          </div>
        </div>

        <div class="line">
          <span class="lab"><i class="mark_icon">*</i>抵押数量：</span>
          <div >
            <el-input v-model.number="data.pledgeNumber" :class="{'error_border':tip_num===3}" min="0" placeholder="请输入抵押数量"
                      type="number" @input="setTip('','')"></el-input>
          </div>
        </div>

        <div class="line">
          <span class="lab"><i class="mark_icon">*</i>抵押金额：</span>
          <div>
            <el-input v-model.number="data.pledgeMoney" :class="{'error_border':tip_num===4}" min="0" placeholder="请输入抵押金额"
                      type="number" @input="setTip('','')"></el-input>
          </div>
        </div>

        <div class="line">
          <span class="lab">是否支付押金：</span>
          <div>
            <el-radio-group v-model="data.isPayPledgeMoney" @change="setTip('','')">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </div>
        </div>

        <div class="line">
          <span class="lab">是否回收空桶：</span>
          <div>
            <el-radio-group v-model="data.isReturn" @change="setTip('','')">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </div>
        </div>


        <p class="error_line">{{ infoTip }}</p>
      </div>
      <div class="box_foot">
        <span @click="closePopup(false)">取消</span>
        <span @click="confirmEdit">确定</span>
      </div>
    </div>
  </div>
</template>

<script>
  import {  updataProduct } from "@/api/data/user/product";

  export default {
    props: ['info'],
    data() {
      return {
        userId:'',
        warehouseId:'',
        isAll:0,
        warehouseName:'',
        numbers:0,
        productNumber:0,
        userName:'',
        parentMenu: [],
        warehouseList:[],
        userList:[],
        infoTip: '',
        tip_num: '',
        loading: false,
        data:{},
      }
    },
    mounted() {
      this.data = this.info;
    },
    methods: {
      // 确认编辑
      confirmEdit() {
        if(this.data.numbers==='') {
          this.setTip(1,'请输入可用量!')
        }
        else if(this.data.productNumber==='') {
          this.setTip(2,'请输入商品数量!')
        }
        else if(this.data.pledgeNumber==='') {
          this.setTip(3,'请输入抵押数量!')
        }
        else if(this.data.pledgeMoney==='') {
          this.setTip(4,'请输入抵押金额!')
        }else {
          this.setTip('','')
          let that = this;
          that.loading = true;
          updataProduct(that.data).then(res => {
            that.closePopup(true);
            that.$message.success({
              message:'编辑成功！',
              duration:1500
            });
          }).catch((e) => {
            that.loading = false;
          });
        }

      },

      setTip(num, text) {
        this.tip_num = num;
        this.infoTip = text
      },

      // 关闭
      closePopup(refresh) {
        this.$emit('listenToChild', {refresh: refresh})
      }
    }
  }
</script>

<style scoped>

</style>
